import { TableColumn } from "@/components/GuatTable/types";
import { Tag } from "@arco-design/web-vue";
import GuatActions from "@/components/GuatActions/index.vue";
import Permissions from "@/constant/permission";

interface Methods {
  del: (typeName: string) => void;
  upd: (record: any) => void;
}

export const createTableColumns = (methods: Methods): TableColumn[] => [
  {
    title: "类型名称",
    dataIndex: "type",
  },
  {
    title: "创建时间",
    dataIndex: "time",
  },
  {
    title: "状态",
    render: (record) => {
      const isUsing = record.status == 0;
      return (
        <Tag size="large" color={isUsing ? "green" : "red"}>
          {isUsing ? "启用" : "禁用"}
        </Tag>
      );
    },
  },
  {
    showTitle: false,
    width: 120,
    render: (record) => (
      <GuatActions
        actions={[
          {
            internal: "edit",
            permission: Permissions.POINT_TYPE_UPD,
            onClick: () => methods.upd(record),
          },
          {
            internal: "delete",
            permission: Permissions.POINT_TYPE_DEL,
            onClick: () => methods.del(record.type),
          },
        ]}
      />
    ),
  },
];
